import random
def contains(x,l):
if(len(l) == 0):
return False
for i in l:
if(x == i):
return True
return False
q = 50
min_val = 1
max_val = 3
a = random.randint(min_val,max_val)
b = random.randint(min_val,max_val)
l = []
ans = 0
fin_ans = 0
while(q > 0):
a = random.randint(min_val,max_val)
b = random.randint(min_val,max_val)
x = (a,b)
while(a == b or (contains(x,l) or contains((x[1],x[0]),l))):
a = random.randint(min_val,max_val)
b = random.randint(min_val,max_val)
x = (a,b)
print("?",a,b)
ans = int(input())
if(ans == -1):
max_val = max(a,b)
q = q - 1
else:
l.append(x)
l.append((x[1],x[0]))
print("?",b,a)
ans2 = int(input())
if(ans != ans2):
fin_ans = ans + ans2
break
max_val = max(max_val,1 + max(ans2,ans))
q = q - 2
print("!",fin_ans)
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 a = 1, b = 2;
while (true) {
std::cout << "? " << a << " " << b << std::endl;
i64 x;
std::cin >> x;
std::cout << "? " << b << " " << a << std::endl;
i64 y;
std::cin >> y;
if (x == -1 || y == -1) break;
if (x != y) {
std::cout << "! " << (x + y) << std::endl;
break;
}
a += 1, b += 1;
}
return 0;
}
1302. Deepest Leaves Sum | 1209. Remove All Adjacent Duplicates in String II |
994. Rotting Oranges | 983. Minimum Cost For Tickets |
973. K Closest Points to Origin | 969. Pancake Sorting |
967. Numbers With Same Consecutive Differences | 957. Prison Cells After N Days |
946. Validate Stack Sequences | 921. Minimum Add to Make Parentheses Valid |
881. Boats to Save People | 497. Random Point in Non-overlapping Rectangles |
528. Random Pick with Weight | 470. Implement Rand10() Using Rand7() |
866. Prime Palindrome | 1516A - Tit for Tat |
622. Design Circular Queue | 814. Binary Tree Pruning |
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |